<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCoursesTable extends Migration
{

    protected $tableName = 'courses';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('series_id')->comment('系列ID');
            $table->unsignedSmallInteger('level')->comment('级别');
            $table->string('name')->comment('课程名称');
            $table->string('description')->default('')->comment('课程描述');
            $table->unsignedInteger('cover')->comment('封面');
            $table->unsignedSmallInteger('lesson_count')->comment('课时数');
            $table->unsignedTinyInteger('is_published')->default(0)->comment('是否发布');

            $table->decimal('price')->comment('单价');
            $table->decimal('discount_price')->comment('优惠单价');

            $table->timestamps();
            $table->softDeletes();

            $table->index('series_id');
        });
        DB::statement("ALTER TABLE `$this->tableName` comment '课程表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
